package com.base.cn.platform.os.controller.mobile.op.giftCard;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * H5礼品卡Controller
 *
 * @author zsw
 * @create 2018-06-15
 */
@Controller
@RequestMapping("/mobile/uc/op/giftcard")
public class MobileGiftCardController extends MobileBaseController {

    @Autowired
    private OpGiftCardCodeService giftCardCodeService;

    /**
     * 我的礼品卡
     * @param request
     * @return
     */
    @RequestMapping("/myGiftCards")
    public String myGiftCard(HttpServletRequest request){
        return resultPage("/op/giftcard/u-giftcard");
    }

    /**
     * 我的礼品卡列表
     * @param request
     * @return
     */
    @RequestMapping("/myAjaxGiftCard")
    public String myAjaxGiftCard(HttpServletRequest request,
                                 Model model,
                                 @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        HashMap<String, Object> giftCard = new HashMap<>();
        giftCard.put("userId",userId);
        giftCard.put("status",1);
        Map<String, Object> giftCardCodeListPage = giftCardCodeService.queryOpGiftCardCodeListPage(currentPage, giftCard, true, false,true);
        model.addAttribute("dataMap",giftCardCodeListPage);
        return resultPage("/op/giftcard/u-ajax-giftcard");
    }

    /**
     * 激活礼卡
     * @param request HttpServletRequest
     * @param id 礼卡ID
     * @param code 礼卡编码
     * @param codePwd 礼卡密码
     * @return Map<String,Object>
     */
    @RequestMapping("/activateGiftCardCode")
    @ResponseBody
    public Map<String,Object> activateGiftCardCode(HttpServletRequest request,
                                                   @RequestParam(value = "id",defaultValue = "0",required = false) BigDecimal id,
                                                   @RequestParam(value = "code",required = false) String code,
                                                   @RequestParam(value = "codePwd",required = false) String codePwd){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        return giftCardCodeService.activateGiftCard(id,userId,code,codePwd);
    }

}
